<?php

// this file accepts POST variables with an article id, and rating, then it
// adds that rating to an article's custom fields

// should only be called after checking that the custom field doesn't exist

// quick and dirty method. look at http://codex.wordpress.org/AJAX_in_Plugins 
// for correct method, as well as http://wordpress.stackexchange.com/questions/14999/cant-access-wordpress-functions-in-file-called-via-ajax
include ('../../../../wp-load.php');

$post_id = $_POST['post_id'];

$rating = strtolower($_POST['rating']);

// make sure rating is valid
if ($rating == 'fresh' ||
	$rating == 'edible' ||
	$rating == 'stale' || 
	$rating == 'moldy' ||
	$rating == 'tasty') 
{
	add_post_meta($post_id, 'rating', $rating, true);
}

?>